const fs = require('fs')
const path = require('path')
const http = require('http')

const server = http.createServer()

server.on('request', (req, res) => {
    let { url, method } = req;
    if (url == '/' || url == '/index.html') {
        url = '/index.html'
    }
    console.log(url,77777)

    
     //res.setHeader('Content-Type', 'text/html;charset=utf8')
    fs.readFile(path.join(__dirname, '/public', url), (err, dataStr) => {
        if (err){
            res.setHeader('Content-Type', 'text/html;charset=utf8')
            res.end('404  哈哈哈')
        } 
        res.end(dataStr)
    })






})

server.listen(2000, () => {
    console.log('服务器:http://127.0.0.1:2000')
})